<template>
	<view class="list" style="background-color: #FFFFFF;">
		<template v-if="isLoad">
			<uni-swipe-action>
				<uni-swipe-action-item 
					v-for="item of topics" 
					:key="item['id']" 
					:right-options="options" 
					@click="operation($event, item['id'])"
				>
					<topic-reply-item :item="item" />
				</uni-swipe-action-item>
			</uni-swipe-action>
		</template>
		<data-empty v-if="!topics.length" />
	</view>
</template>

<script>
	export default {
		data (){
			return {
				topics: [],
				isLoad: false,
				options:[{
					text: '编辑',
					style: {
						backgroundColor: '#cccccc'
					}
				}]
			}
		},
		onLoad (){
			const { loginname } = this.$store.state.user_message
			this.getAuthorDetail(loginname)
		},
		methods: {
			async getAuthorDetail (author){
				uni.showLoading()
				let result = await this.$request.get('/user/'+author)
				let { data } = result
				if(result.success){
					this.topics = data['recent_topics']
				}
				this.isLoad = true
				uni.hideLoading()
			},
			// 编辑
			operation(e, id){
				if(e.content.text === '编辑'){
					uni.setStorageSync('topic_update_id', id)
					uni.switchTab({
						url: '/pages/publish/index'
					})
				}
			}
		}
	}
</script>

<style>
</style>
